package com.wl156.activities.publish;

import org.ksoap2.serialization.SoapObject;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;

import com.wl156.R;
import com.wl156.activities.find.CarMessageInfo;
import com.wl156.adapters.TruckMessageAdapter;
import com.wl156.model.WebServiceClient.OnWebServiceCompleteListener;

public class NewGoodInfoAfter extends NewInfoAfterBase {

	private TruckMessageAdapter mAdapter;

	String startLocationLv1 = "";
	String startLocationLv2 = "";
	String startLocationLv3 = "";
	String endLocationLv1 = "";
	String endLocationLv2 = "";
	String endLocationLv3 = "";
	String setOffDate = "";
	String freightName = "";
	String freightTonnage = "";
	String freightTruckLengthRequired = "";
	String freightTonnageSymbol = "";
	String setOffDateSymbol = "";
	String freightTruckLengthRequiredSymbol = "";
	String truckType = "";
	String truckTonnage = "";
	String truckTonnageSymBol = "";
	String truckLength = "";
	String truckLengthSymbol = "";
	
	protected Class getGoodOrCarInfoClass() {
		return CarMessageInfo.class;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		mHeaderStub.setLayoutResource(R.layout.item_truck_message_header);
		mHeaderStub.inflate();
		mTipView.setText("以下显示最符合匹配的十台货车");
		goodInfo.setText("货车");

		Bundle extras = getIntent().getExtras();
		startLocationLv1 = extras.getString("startLocationLv1");
		startLocationLv2 = extras.getString("startLocationLv2");
		endLocationLv1 = extras.getString("endLocationLv1");
		// startLocationLv3 = extras.getString("startLocationLv3");
		// endLocationLv1 = extras.getString("endLocationLv1");
		// endLocationLv2 = extras.getString("endLocationLv2");
		// endLocationLv3 = extras.getString("endLocationLv3");
		// setOffDate = extras.getString("setOffDate");
		// freightName = extras.getString("freightName");
		// freightTonnage = extras.getString("freightTonnage");
		// freightTruckLengthRequired = extras
		// .getString("freightTruckLengthRequired");
		freightTonnageSymbol = "";
		setOffDateSymbol = "";
		freightTruckLengthRequiredSymbol = "";
		truckType = "";
		truckTonnage = "";
		truckTonnageSymBol = "";
		truckLength = "";
		truckLengthSymbol = "";

		mWebServiceClient.commonFindTrunkMessageAsync(mCertificate,
				startLocationLv1, startLocationLv2, startLocationLv3,
				endLocationLv1, endLocationLv2, endLocationLv3, truckType,
				truckTonnage, truckTonnageSymBol, truckLength,
				truckLengthSymbol, setOffDate, setOffDateSymbol, 0, 10,
				mOnWebServiceCompleteListener);
	}

	OnWebServiceCompleteListener mOnWebServiceCompleteListener = new OnWebServiceCompleteListener() {
		@Override
		public void onPostExecute(Object result) {
			if (result instanceof SoapObject) {
				SoapObject so = (SoapObject) result;
				if (so.getPropertyCount() == 0) {
				} else if (so.getPropertyCount() == 1
						&& ((SoapObject) so.getProperty(0)).getPropertyCount() == 0) {
					SoapObject so1 = (SoapObject) so.getProperty(0);
					if (so1.getPropertyCount() == 0) {
					}
				} else {
					mAdapter = new TruckMessageAdapter(NewGoodInfoAfter.this,
							so);
					mListView.setAdapter(mAdapter);
				}
			} else {
				AlertDialog.Builder builder = new Builder(NewGoodInfoAfter.this);
				builder.setMessage("网络请求超时！");
				builder.setPositiveButton("重试",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								mWebServiceClient.commonFindTrunkMessageAsync(
										mCertificate, startLocationLv1,
										startLocationLv2, startLocationLv3,
										endLocationLv1, endLocationLv2,
										endLocationLv3, truckType,
										truckTonnage, truckTonnageSymBol,
										truckLength, truckLengthSymbol,
										setOffDate, setOffDateSymbol, 0, 10,
										mOnWebServiceCompleteListener);
							}
						});
				builder.setNegativeButton("取消",
						new DialogInterface.OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								finish();
							}
						});
				builder.show();
			}
		}
	};
}
